//
//  ViewController.swift
//  OpenAppOnSwift
//
//  Created by 李禹 on 15/5/25.
//  Copyright (c) 2015年 dayu. All rights reserved.
//

import UIKit

class ViewController: UITableViewController {
    
    var _dataList: NSMutableArray? = nil;
    var dataList: NSMutableArray {
        if _dataList != nil {
            return _dataList!;
        }
        _dataList = NSMutableArray();
        var item: String;
        for index in 1...10 {
            item = NSString(format: "Product%.2d", index) as String;
            _dataList!.addObject(item);
        }
        return _dataList!;
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataList.count;
    }
    
    static let identifier = "DetailCell";
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        var cell = tableView.dequeueReusableCellWithIdentifier(ViewController.identifier) as? UITableViewCell;
        if cell == nil {
            cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: ViewController.identifier);
        }
        cell!.textLabel?.text = self.dataList[indexPath.row] as? String;
        return cell!;
    }
    
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let detailVC = DYDetailViewController();
        detailVC.item = self.dataList[indexPath.row] as? String;
        self.navigationController! .pushViewController(detailVC, animated: true);
    }
}

